package com.taoyibao.hongcanting.ui.home.views;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.TextView;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.BaseRelativeLayout;
import com.taoyibao.hongcanting.constant.CodeConstant;
import com.taoyibao.hongcanting.model.DishModel;
import com.taoyibao.hongcanting.utils.CodeUtils;
import com.taoyibao.hongcanting.utils.GlideUtil;
import com.taoyibao.hongcanting.widget.HorizontalLineTextView;

/**
 * @author TangAnna
 * @description: 分类下面的菜品item
 * @date :${DATA} 19:18
 */
public class ItemMenuListArea extends BaseRelativeLayout<DishModel> {
    /**
     * 原价
     */
    private HorizontalLineTextView mTvPrice;
    /**
     * 优惠价
     */
    private TextView mTvDiscountPrice;
    /**
     * 图片
     */
    private ImageView mIvPic;
    /**
     * 菜名
     */
    private TextView mTvName;
    /**
     * 数量控制器
     */
    private CountControllerArea mCountControllerArea;

    /**
     * 食材
     */
    private TextView mTvFrom;

    public ItemMenuListArea(Context context) {
        super(context);
    }

    public ItemMenuListArea(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ItemMenuListArea(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void initView(Context context, AttributeSet attrs, int defStyleAttr) {
        mTvPrice = findViewById(R.id.tv_item_menu_list_price);
        mTvDiscountPrice = findViewById(R.id.tv_item_menu_list_discount_price);
        mIvPic = findViewById(R.id.iv_item_menu_list_pic);
        mTvName = findViewById(R.id.tv_item_menu_list_name);
        mCountControllerArea = findViewById(R.id.cca_itemMenu_controller);
        mTvFrom = findViewById(R.id.tv_item_menu_list_from);
        mCountControllerArea.setSource(CodeConstant.EVENT_SOURCE_MENU);
    }

    @Override
    public void setData(DishModel data) {
        //菜名
        if (!TextUtils.isEmpty(data.dish_name)) {
            mTvName.setText(data.dish_name);
        }
        //图片
        GlideUtil.getInstance().loadDefaultImage(getContext(), data.dish_pic, mIvPic);
        //优惠价
        mTvDiscountPrice.setText(CodeUtils.formatAmountUnit(data.dish_discount_price) + "/" + data.dish_unit);
        //原价
        mTvPrice.setData(CodeUtils.formatAmountUnit(data.dish_price) + "/" + data.dish_unit);
        //数量
        mCountControllerArea.setData(data);
        //食材
        mTvFrom.setText("食材:" + data.dish_form);
    }

    @Override
    protected int bindLayout() {
        return R.layout.item_menu_list;
    }
}
